package io.renren.minimito.service.impl;

import com.alibaba.druid.util.StringUtils;
import io.renren.minimito.entity.ImRequestEntity;
import org.springframework.stereotype.Service;

import java.util.Arrays;
import java.util.List;
import java.util.Map;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import io.renren.common.utils.PageUtils;
import io.renren.common.utils.Query;

import io.renren.minimito.dao.ImUserDao;
import io.renren.minimito.entity.ImUserEntity;
import io.renren.minimito.service.ImUserService;


@Service("imUserService")
public class ImUserServiceImpl extends ServiceImpl<ImUserDao, ImUserEntity> implements ImUserService {

    @Override
    public PageUtils queryPage(Map<String, Object> params) {
//        IPage<ImUserEntity> page = this.page(
//                new Query<ImUserEntity>().getPage(params),
//                new QueryWrapper<ImUserEntity>()
//        );
//
//        return new PageUtils(page);}
        QueryWrapper<ImUserEntity> wrapper = new QueryWrapper<>();
        String key = (String) params.get("key");
        if (!StringUtils.isEmpty(key)){
            wrapper.eq("id",key)
                    .or().eq("username",key)
                    .or().like("nickname",key)
            ;
        }
        IPage<ImUserEntity> page = this.page(
                new Query<ImUserEntity>().getPage(params),
                wrapper
        );

        return new PageUtils(page);
    }

    @Override
    public void banOrOpen(Long id) {
        ImUserEntity entity = getById(id);
        if (entity.getIsDeleted()==0){
            baseMapper.ban(id);
        }
        else baseMapper.open(id);
    }

}